import cn.bugstack.mybatis.binding.MapperRegistry;
import cn.bugstack.mybatis.binding.session.SqlSession;
import cn.bugstack.mybatis.binding.session.SqlSessionFactory;
import cn.bugstack.mybatis.binding.session.defaults.DefaultSqlSessionFactory;
import cn.bugstack.mybatis.dao.IUserDao;
import org.junit.Test;

/**
 * 1. 注册器扫描dao接口 为每个dao接口创建一个代理工厂 用来生产代理类
 * 2. 使用注册器制造sql工厂 来制造sqlSession
 * 3. 通过sqlSession获取 对用dao的代理类
 * 4. 执行查询
 * */
public class ApiTest {
    @Test
    public void test() {
        //1. 注册Mapper
        MapperRegistry mapperRegistry = new MapperRegistry();
        mapperRegistry.addMappers("cn.bugstack.mybatis.dao");
        //2. 从sqlSession工厂获取sqlSession
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(mapperRegistry);
        SqlSession sqlSession = sqlSessionFactory.openSqlSession();
        //3. 获取映射器对象
        IUserDao userDao = sqlSession.getMapper(IUserDao.class);
        //4. 执行查询
        String res = userDao.queryUserName("1001");
        System.out.println("测试结果：" + res);

    }
}
